package org.easytouseit.rabbitmq.topic.consumer;

import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 消费者
 *
 * @author guojm
 * @version V1.0
 * @date 2018-12-28 下午 15:18
 */
@Component
@RabbitListener(queues = TopicRabbitMQConfig.TOPIC_QUEUE_ONE, containerFactory="rabbitListenerContainerFactory")
public class TopicMsgReceiverOne {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @RabbitHandler
    public void process(String content, Channel channel, Message message) {
        logger.info("消费者TopicMsgReceiverOne接收处理队列:{}当中的消息:{}",TopicRabbitMQConfig.TOPIC_QUEUE_ONE,content);
        try {
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
